package com.george.minio.config;

import io.minio.MinioClient;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @title: com.george.config.MinioConfig.java
 * @description: Minio对象存储服务配置类
 * @author: George
 * @date: 2023/5/16 16:19
 */
@Configuration
@Component
@Slf4j
@Data
public class MinioConfig {
    @Value("${minio.endpoint}")
    private String endpoint;

    @Value("${minio.port}")
    private int port;

    @Value("${minio.accessKey}")
    private String accessKey;

    @Value("${minio.secretKey}")
    private String secretKey;

    @Value("${minio.secure}")
    private Boolean secure;

    @Value("${minio.bucketName}")
    private String bucketName;

    @Bean
    public MinioClient getMinioClient() throws Exception {
        log.info("Minio 初始化 endpoint:{},port:{},accessKey:{},secretKey:{}",endpoint,port,accessKey,secretKey);
        MinioClient minioClient = MinioClient.builder().endpoint(endpoint, port, secure)
                .credentials(accessKey, secretKey)
                .build();
        log.info("Minio 初始化完成，Buckets:{}",minioClient.listBuckets());
        return minioClient;
    }
}

